import { Base } from '../../utils/base.js';
Date.prototype.Format = function (fmt) { //author: meizz
    var o = {
        "M+": this.getMonth() + 1, //月份
        "d+": this.getDate(), //日
        "h+": this.getHours(), //小时
        "m+": this.getMinutes(), //分
        "s+": this.getSeconds(), //秒
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
        "S": this.getMilliseconds() //毫秒
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
        if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
};
class Order extends Base {
    constructor() {
        super()
    }
    //获取订单
    getOrder(params, callback) {
        let url = '/purchase/order/list'
        var reType = 'POST';
        this.commonRequest(url, reType, params, callback);
    }
    //删除订单
    deleteOrder(params, callback) {
        let url = '/purchase/order/delete'
        var reType = 'POST';
        this.commonRequest(url, reType, params, callback);
    }
    // 获取不同订单数量
    getOrderCount(params,callback){
        let url = '/purchase/order/getOrderCount'
        var reType = 'POST';
        this.commonRequest(url, reType, params, callback);
    }
    //付款
    wxPay(params, callback) {
        let url = "/purchase/pay/doUnifiedOrder";
        var reType = 'POST';        
        this.commonRequest(url, reType, params, callback);
    } 
    // 根据id获取单个地址
    getUserAddressById(params, callback) {
        var url = '/purchase/user/getUserAddressById';
        var reType = 'POST';
        this.commonRequest(url, reType,params, callback);
    }
    // 减库存接口
    reduceGoodsStock(params,callback){
        var url = '/purchase/order/reduceGoodsStock'
        var reType = 'POST';
        this.commonRequest(url, reType, params, callback);
    }
    commonRequest(url, reType, params, callback) {
        var that = this;
        var param = {
            url: url,
            type: reType,
            data: params,
            sCallback: function (data) {
                typeof callback == 'function' && callback(data);
            },
            eCallback: data => {
                callback && callback({ status: false,data: data });
            }
        };
        this.request(param);
    }
    
    formate(fmt, data){
        var data = data ? data : 'yyyy-MM-dd hh:mm:ss'
        return (new Date(fmt)).Format(data)
    }
}
module.exports = {
    Order
}